package com.anye.greendao.gen;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.yoyo.yyadsdk.util.StringConverter;
import com.yoyo.yyadsdk.util.StringToUserActive;
import java.util.List;

import com.yoyo.yyadsdk.bean.dao.RuleListEntity;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "RULE_LIST_ENTITY".
*/
public class RuleListEntityDao extends AbstractDao<RuleListEntity, Long> {

    public static final String TABLENAME = "RULE_LIST_ENTITY";

    /**
     * Properties of entity RuleListEntity.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property _id = new Property(0, Long.class, "_id", true, "_id");
        public final static Property RuleId = new Property(1, long.class, "ruleId", false, "RULE_ID");
        public final static Property Type = new Property(2, int.class, "type", false, "TYPE");
        public final static Property InWhiteRule = new Property(3, boolean.class, "inWhiteRule", false, "IN_WHITE_RULE");
        public final static Property InBlackRule = new Property(4, boolean.class, "inBlackRule", false, "IN_BLACK_RULE");
        public final static Property Pkg = new Property(5, String.class, "pkg", false, "PKG");
        public final static Property Model = new Property(6, String.class, "model", false, "MODEL");
        public final static Property Channel = new Property(7, String.class, "channel", false, "CHANNEL");
        public final static Property Country = new Property(8, String.class, "country", false, "COUNTRY");
        public final static Property City = new Property(9, String.class, "city", false, "CITY");
        public final static Property Imei = new Property(10, String.class, "imei", false, "IMEI");
        public final static Property UserActive = new Property(11, String.class, "userActive", false, "USER_ACTIVE");
    }

    private final StringConverter pkgConverter = new StringConverter();
    private final StringConverter modelConverter = new StringConverter();
    private final StringConverter channelConverter = new StringConverter();
    private final StringConverter countryConverter = new StringConverter();
    private final StringConverter cityConverter = new StringConverter();
    private final StringConverter imeiConverter = new StringConverter();
    private final StringToUserActive userActiveConverter = new StringToUserActive();

    public RuleListEntityDao(DaoConfig config) {
        super(config);
    }
    
    public RuleListEntityDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"RULE_LIST_ENTITY\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: _id
                "\"RULE_ID\" INTEGER NOT NULL UNIQUE ," + // 1: ruleId
                "\"TYPE\" INTEGER NOT NULL ," + // 2: type
                "\"IN_WHITE_RULE\" INTEGER NOT NULL ," + // 3: inWhiteRule
                "\"IN_BLACK_RULE\" INTEGER NOT NULL ," + // 4: inBlackRule
                "\"PKG\" TEXT," + // 5: pkg
                "\"MODEL\" TEXT," + // 6: model
                "\"CHANNEL\" TEXT," + // 7: channel
                "\"COUNTRY\" TEXT," + // 8: country
                "\"CITY\" TEXT," + // 9: city
                "\"IMEI\" TEXT," + // 10: imei
                "\"USER_ACTIVE\" TEXT);"); // 11: userActive
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"RULE_LIST_ENTITY\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, RuleListEntity entity) {
        stmt.clearBindings();
 
        Long _id = entity.get_id();
        if (_id != null) {
            stmt.bindLong(1, _id);
        }
        stmt.bindLong(2, entity.getRuleId());
        stmt.bindLong(3, entity.getType());
        stmt.bindLong(4, entity.getInWhiteRule() ? 1L: 0L);
        stmt.bindLong(5, entity.getInBlackRule() ? 1L: 0L);
 
        List pkg = entity.getPkg();
        if (pkg != null) {
            stmt.bindString(6, pkgConverter.convertToDatabaseValue(pkg));
        }
 
        List model = entity.getModel();
        if (model != null) {
            stmt.bindString(7, modelConverter.convertToDatabaseValue(model));
        }
 
        List channel = entity.getChannel();
        if (channel != null) {
            stmt.bindString(8, channelConverter.convertToDatabaseValue(channel));
        }
 
        List country = entity.getCountry();
        if (country != null) {
            stmt.bindString(9, countryConverter.convertToDatabaseValue(country));
        }
 
        List city = entity.getCity();
        if (city != null) {
            stmt.bindString(10, cityConverter.convertToDatabaseValue(city));
        }
 
        List imei = entity.getImei();
        if (imei != null) {
            stmt.bindString(11, imeiConverter.convertToDatabaseValue(imei));
        }
 
        List userActive = entity.getUserActive();
        if (userActive != null) {
            stmt.bindString(12, userActiveConverter.convertToDatabaseValue(userActive));
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, RuleListEntity entity) {
        stmt.clearBindings();
 
        Long _id = entity.get_id();
        if (_id != null) {
            stmt.bindLong(1, _id);
        }
        stmt.bindLong(2, entity.getRuleId());
        stmt.bindLong(3, entity.getType());
        stmt.bindLong(4, entity.getInWhiteRule() ? 1L: 0L);
        stmt.bindLong(5, entity.getInBlackRule() ? 1L: 0L);
 
        List pkg = entity.getPkg();
        if (pkg != null) {
            stmt.bindString(6, pkgConverter.convertToDatabaseValue(pkg));
        }
 
        List model = entity.getModel();
        if (model != null) {
            stmt.bindString(7, modelConverter.convertToDatabaseValue(model));
        }
 
        List channel = entity.getChannel();
        if (channel != null) {
            stmt.bindString(8, channelConverter.convertToDatabaseValue(channel));
        }
 
        List country = entity.getCountry();
        if (country != null) {
            stmt.bindString(9, countryConverter.convertToDatabaseValue(country));
        }
 
        List city = entity.getCity();
        if (city != null) {
            stmt.bindString(10, cityConverter.convertToDatabaseValue(city));
        }
 
        List imei = entity.getImei();
        if (imei != null) {
            stmt.bindString(11, imeiConverter.convertToDatabaseValue(imei));
        }
 
        List userActive = entity.getUserActive();
        if (userActive != null) {
            stmt.bindString(12, userActiveConverter.convertToDatabaseValue(userActive));
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public RuleListEntity readEntity(Cursor cursor, int offset) {
        RuleListEntity entity = new RuleListEntity( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // _id
            cursor.getLong(offset + 1), // ruleId
            cursor.getInt(offset + 2), // type
            cursor.getShort(offset + 3) != 0, // inWhiteRule
            cursor.getShort(offset + 4) != 0, // inBlackRule
            cursor.isNull(offset + 5) ? null : pkgConverter.convertToEntityProperty(cursor.getString(offset + 5)), // pkg
            cursor.isNull(offset + 6) ? null : modelConverter.convertToEntityProperty(cursor.getString(offset + 6)), // model
            cursor.isNull(offset + 7) ? null : channelConverter.convertToEntityProperty(cursor.getString(offset + 7)), // channel
            cursor.isNull(offset + 8) ? null : countryConverter.convertToEntityProperty(cursor.getString(offset + 8)), // country
            cursor.isNull(offset + 9) ? null : cityConverter.convertToEntityProperty(cursor.getString(offset + 9)), // city
            cursor.isNull(offset + 10) ? null : imeiConverter.convertToEntityProperty(cursor.getString(offset + 10)), // imei
            cursor.isNull(offset + 11) ? null : userActiveConverter.convertToEntityProperty(cursor.getString(offset + 11)) // userActive
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, RuleListEntity entity, int offset) {
        entity.set_id(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setRuleId(cursor.getLong(offset + 1));
        entity.setType(cursor.getInt(offset + 2));
        entity.setInWhiteRule(cursor.getShort(offset + 3) != 0);
        entity.setInBlackRule(cursor.getShort(offset + 4) != 0);
        entity.setPkg(cursor.isNull(offset + 5) ? null : pkgConverter.convertToEntityProperty(cursor.getString(offset + 5)));
        entity.setModel(cursor.isNull(offset + 6) ? null : modelConverter.convertToEntityProperty(cursor.getString(offset + 6)));
        entity.setChannel(cursor.isNull(offset + 7) ? null : channelConverter.convertToEntityProperty(cursor.getString(offset + 7)));
        entity.setCountry(cursor.isNull(offset + 8) ? null : countryConverter.convertToEntityProperty(cursor.getString(offset + 8)));
        entity.setCity(cursor.isNull(offset + 9) ? null : cityConverter.convertToEntityProperty(cursor.getString(offset + 9)));
        entity.setImei(cursor.isNull(offset + 10) ? null : imeiConverter.convertToEntityProperty(cursor.getString(offset + 10)));
        entity.setUserActive(cursor.isNull(offset + 11) ? null : userActiveConverter.convertToEntityProperty(cursor.getString(offset + 11)));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(RuleListEntity entity, long rowId) {
        entity.set_id(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(RuleListEntity entity) {
        if(entity != null) {
            return entity.get_id();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(RuleListEntity entity) {
        return entity.get_id() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
